package com.xiaouyudeguang.common.collect;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class SortMap<E> extends TreeMap<Comparable<? extends Number>, List<E>> {

    private static final long serialVersionUID = 1L;

    public void add(Comparable<? extends Number> key, E value) {
        List<E> list = get(key);
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(value);
        put(key, list);
    }

    public List<E> getValues() {
        List<E> list = new ArrayList<>();
        for (Map.Entry<Comparable<? extends Number>, List<E>> entry : this.entrySet()) {
            list.addAll(entry.getValue());
        }
        return list;
    }

    public static void main(String[] args) {
        SortMap<String> map = new SortMap<>();
        map.add(100, "wewqewq1");
        map.add(3, "wewqewq3");
        map.add(1000, "wewqewq1");
        map.add(2, "wewqewq2");
        map.add(2, "wewqewq2");
        map.add(3, "wewqewq3");
        map.add(2, "wewqewq2");
        map.add(1, "wewqewq11111");
        System.out.println(map);
    }
}